<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title> CX | Registration Page</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.7 -->
    <link rel="stylesheet" href="../../bower_components/bootstrap/dist/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="../../bower_components/font-awesome/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="../../bower_components/Ionicons/css/ionicons.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="../../dist/css/AdminLTE.min.css">


    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->

    <!-- Google Font -->
    <link rel="stylesheet"
          href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
</head>
<body class="hold-transition register-page">
<div class="register-box">
    <div class="register-logo">
        <a href="#"><b>用户注册</b></a>
    </div>

    <div class="register-box-body">
        <p class="login-box-msg">Register a new membership</p>

        <!--<form action="/api/v1/addUser" method="post">-->
        <div class="form-group has-feedback">
            <input type="text" id='UserName' class="form-control" placeholder="UserName"
                   onblur="checkUserName()">
            <p><span id="warn" style="display:none">用户已存在</span></p>
            <span class="glyphicon glyphicon-user form-control-feedback"></span>
        </div>

        <div class="form-group has-feedback">
            <input type="password" id='password' class="form-control" placeholder="Password">
            <span class="glyphicon glyphicon-lock form-control-feedback"></span>
        </div>
        <div class="form-group has-feedback">
            <input type="date" id="birthday" class="form-control" placeholder="生日">
            <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
        </div>
        <div class="form-group has-feedback">
            <select class="form-control" id="sex">
                <option value="男">男</option>
                <option value="女">女</option>
            </select>
        </div>
        <div class="row">
            <div class="col-xs-4"></div>
            <div class="col-xs-4">
                <button type="submit" id='tijiao' class="btn btn-primary btn-block btn-flat" >Register</button>
            </div>
        </div>
        <a href="/" class="text-center">I already have a membership</a>
    </div>
</div>

<!-- jQuery 3 -->
<script src="../../bower_components/jquery/dist/jquery.min.js"></script>
<!-- Bootstrap 3.3.7 -->
<script src="../../bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- iCheck -->


<script>

    $('#tijiao').click(function () {
        console.log($("#UserName").val())
        var info = {
            "id": null,
            "userName": $("#UserName").val(),
            "password": $("#password").val(),
            "sex": $("#sex").val(),
            "birthday": $("#birthday").val()
        };

        $.ajax({
            type: 'post',
            url: "/admin/user/addUser",
            headers: {'Content-type': 'application/json;charset=UTF-8'},
            data: JSON.stringify(info),
            dataType: "json",
            success: function (data) {
                alert("注册成功")
                window.location.href = "/admin/login";
            },
            error: function (data) {
                console.log(data);
                alert("异常！");
            }
        })
    })

    function checkUserName() {

        var userName =  $("#UserName").val();
        // var info = {
        //     "userName": $("#UserName").val()
        // }
        $.ajax({
            type: 'get',
            url: "/admin/user/toSelectByUsername?userName="+userName,
            //headers: {'Content-type': 'application/json;charset=UTF-8'},
            success: function (result) {

                if (result == 1) {
                    $("#warn").show();//显示span标签
                    $("#warn").css("color","red");
                }else {
                    $("#warn").hide();
                }
            },
            error: function (result) {
                alert("异常");

            }
        })
    }

</script>
</body>
</html>
